package com.BigDecimal;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalDemo2 {
    public static void main(String[] args) {
   //​    张三,男,20,79.5     李四,女,21,80.2
   //      王五,男,22,77.9     周六,男,20,55.8  赵七,女,21,99.9
        Student student1 = new Student("张三","男",20,79.5);
        Student student2 = new Student("李四","女",21,80.2);
        Student student3 = new Student("王五","男",22,77.9);
        Student student4 = new Student("周六","男",20,55.8);
        Student student5 = new Student("赵七","女",21,99.9);
       //并计算5名学员的“平均分”(四舍五入到小数点后2位)。
        BigDecimal sum=new BigDecimal(0);
        sum=sum.add(BigDecimal.valueOf(student1.getNumber()));
        sum=sum.add(BigDecimal.valueOf(student2.getNumber()));
        sum=sum.add(BigDecimal.valueOf(student3.getNumber()));
        sum=sum.add(BigDecimal.valueOf(student4.getNumber()));
        sum=sum.add(BigDecimal.valueOf(student5.getNumber()));
      double avg=sum.divide(BigDecimal.valueOf(5),2, RoundingMode.HALF_UP).doubleValue();
        System.out.println(avg);
    }
}
class Student{
    //定义学员类，属性：姓名、性别、年龄、分数
    private String name;
    private String sex;
    private int age;
    private double number;

    public Student() {
    }

    public Student(String name, String sex, int age, double number) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getNumber() {
        return number;
    }

    public void setNumber(double number) {
        this.number = number;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (age != student.age) return false;
        if (Double.compare(student.number, number) != 0) return false;
        if (name != null ? !name.equals(student.name) : student.name != null) return false;
        return sex != null ? sex.equals(student.sex) : student.sex == null;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", number=" + number +
                '}';
    }
}
